package com.zlzlib.manager.controller;

import com.zlzlib.common.bean.PageDataVo;
import com.zlzlib.common.bean.ResultVo;
import com.zlzlib.common.config.BaseUrlHead;
import com.zlzlib.log.bean.dto.ReqLogDto;
import com.zlzlib.log.bean.vo.LogListVo;
import com.zlzlib.log.service.LogSaveService;
import com.zlzlib.log.service.LogService;
import com.zlzlib.manager.bean.dto.LogSystemDto;
import com.zlzlib.manager.bean.vo.LogSystemVo;
import com.zlzlib.vuePage.VuePageUtils;
import com.zlzlib.vuePage.bean.vo.FindPageVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统日志
 *
 * @DateTime: 2023/12/15 17:45
 * @Author zlz
 * @Version 1.0
 */
@BaseUrlHead
@RestController
@RequestMapping("/logSystem")
@RequiredArgsConstructor
public class LogSystemController {

    @Value("${logSystem.show:false}")
    private boolean isShowLog = false;

    private final LogService logService;

    private final LogSaveService logSaveService;

    @GetMapping({"/query"})
    @ResponseBody
    public ResultVo queryLogSystem(LogSystemDto dto) {
        if(!isShowLog){
            return ResultVo.error("当前未开启日志查询");
        }
        PageDataVo vo = new PageDataVo();
        LogListVo logListVo = logService.getLogPage(dto);
        vo.setTotal((int) logListVo.getTotals());
        vo.setDataList(logListVo.getData());
        return ResultVo.success(vo);
    }

    @GetMapping({"/getLogFilter"})
    @ResponseBody
    public ResultVo getLogFilter() {
        if(!isShowLog){
            return ResultVo.error("当前未开启日志查询");
        }
        FindPageVo vo = new FindPageVo();
        vo.setTable(VuePageUtils.getTableItemList(LogSystemVo.class));
        vo.setFind(VuePageUtils.getFormItemList(ReqLogDto.class));
        return ResultVo.success(vo);
    }

    @GetMapping({"/getLogSaveStatus"})
    @ResponseBody
    public ResultVo getLogSaveStatus() {
        if(!isShowLog){
            return ResultVo.error("当前未开启日志查询");
        }
        return ResultVo.success(logSaveService.getStatus());
    }
}
